#include <stdio.h>
#include <string.h>
#include "queue.h"

char g_queue_buf[100*1024*1024]; //100MB
char p_data[102400];

queue_t q;

int main(int argc, char **argv)
{
	int i = 0;	
	int ret;

	if (!queue_create(&q, g_queue_buf, sizeof(g_queue_buf)) )
	{
		printf("queue_create() success\n");
	}
	else
	{
		printf("queue_create() fail\n");
		return -1;
	}

	while (1)
	{
		i = 0;

		while (1)
		{
			sprintf(p_data, "num-----%d", i);
			ret = queue_write(&q, p_data, sizeof(p_data));
			if (!ret)
			{
				printf("queue_write() success, p_data:%s\n", p_data);
			}
			else
			{
				printf("queue_write() fail, p_data:%s,ret:%d\n", p_data, ret);
				break;
			}
			i++;
		}

		sleep(3);

		while (1)
		{
			memset(p_data, 0, sizeof(p_data));
			ret = queue_read(&q, p_data, sizeof(p_data));
			//ret = queue_read(&q, p_data, 100); //return -3
			if (ret >= 0)
			{
				printf("queue_read() success, p_data:%s, ret:%d\n", p_data, ret);
			}
			else	
			{
				printf("queue_read() fail, p_data:%s,ret:%d\n", p_data, ret);
				sleep(5);
				break;
			}
		}
		
		printf("----------------------------------\n");
		sleep(2);
	}	

	return 0;
}
